from flask import Flask,request
from flask import  render_template


app = Flask(__name__)

#1.登记路由：route
@app.route('/',methods=['GET','POST']) # / 根路径，首页，相对路径
# 2.视图函数，返回值为页面的显示信息，文本txt,html,json等
def hello_world():
    return '<h1><font-style = "color:red">Hello World!</font></h1>'

# 练习：请大家尝试写一个页面 路由为 /index, 视图函数返回的内容为 <h1>这是首页</h1>
@app.route('/index',methods=['GET','POST'])
def index():
    # 用户输入的信息是在 request 中的
    print(request.form['firstname'])
    print(request.form['lastname'])

    return render_template('index.html')
@app.route('/result',methods=['GET','POST'])
def build_name():
    first_name = request.form['firstname']
    last_name = request.form['lastname']
    full_name = first_name.title()+' '+ last_name.title()
    return render_template('fullname_result.html',fullname=full_name)

if __name__ == '__main__':
    app.run()
